import requests
from lxml import etree

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36"
}
# 发起请求
response = requests.get("https://movie.douban.com/chart", headers=headers)
# 获取响应内容
html_text = response.text

# 将html文本转换成对象
html = etree.HTML(html_text)

# 获取所有的table
tables = html.xpath("//div[@class='article']/div/div/table")

for table in tables:
    name = table.xpath("./tr/td[2]/div/a/text()")[0].replace("/", "").strip()
    context = table.xpath("./tr/td[2]/div/p/text()")[0]
    score = table.xpath("./tr/td[2]/div/div/span[2]/text()")[0]
    score_num = table.xpath("./tr/td[2]/div/div/span[3]/text()")[0]

    print(name, score, score_num, context)
